<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  likelist.php
//  phpweb
//  
//  Created by WillLee on 2011-07-06.
//  Copyright 2011 lishuzu. All rights reserved.
// 


class Relate extends CI_Controller {

	function __construct()
	{
		parent::__construct();
	}
	
	public function index()
	{
		$subjectenc = rawurlencode(strip_tags($_GET['subjectenc']));
		$messageenc = rawurlencode(strip_tags(preg_replace("/\[.+?\]/U", '', $_GET['messageenc'])));
		$charset = strtolower($this->config->item('charset'));
		$data = @implode('', file("http://keyword.discuz.com/related_kw.html?title=$subjectenc&content=$messageenc&ics=".$charset."&ocs=".$charset));
		if($data) {
			$parser = xml_parser_create();
			xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
			xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
			xml_parse_into_struct($parser, $data, $values, $index);
			xml_parser_free($parser);

			$kws = array();

			foreach($values as $valuearray) {
				if($valuearray['tag'] == 'kw' || $valuearray['tag'] == 'ekw') {
					if(PHP_VERSION > '5' && $charset != 'utf-8') {
						$kws[] = siconv(trim($valuearray['value']), $charset, 'utf-8');//编码转换
					} else {
						$kws[] = trim($valuearray['value']);
					}
				}
			}

			$return = '';
			if($kws) {
				foreach($kws as $kw) {
					$kw = shtmlspecialchars($kw);
					$return .= $kw.' ';
				}
				$return = trim($return);
			}
			showjsonmessage($return, 1);
		} else {
			showjsonmessage(' ', 0);
		}
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */